﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Globalization;

namespace devtm.Verbatim.CustomConverters
{

    public abstract class Converter<TSource, TTarget> : Converter<TSource, TTarget, object>
    {

        
    }

    public abstract class Converter<TSource, TTarget, TParameter> : IConverter<TSource, TTarget, TParameter>
        where TParameter : class
    {


        /// <summary>
        /// Initializes a new instance of the <see cref="Converter&lt;TSource, TTarget&gt;"/> class.
        /// </summary>
        public Converter()
        {
        }


        /// <summary>
        /// Gets the type of the source. 
        /// </summary>
        /// <returns></returns>
        public static Type GetSourceType()
        {
            return typeof(TSource);
        }


        /// <summary>
        /// Gets the type of the target.
        /// </summary>
        /// <returns></returns>
        public static Type GetTargetType()
        {
            return typeof(TTarget);
        }


        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public TTarget Convert(TSource value)
        {
            return Convert(value, default(TParameter), System.Globalization.CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns></returns>
        public TTarget Convert(TSource value, TParameter parameter)
        {
            return Convert(value, parameter, System.Globalization.CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        public abstract TSource Convert(TTarget value, TParameter parameter, System.Globalization.CultureInfo culture);





        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public TSource Convert(TTarget value)
        {
            return Convert(value, default(TParameter), System.Globalization.CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns></returns>
        public TSource Convert(TTarget value, TParameter parameter)
        {
            return Convert(value, parameter, System.Globalization.CultureInfo.CurrentCulture);
        }

        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        public abstract TTarget Convert(TSource value, TParameter parameter, System.Globalization.CultureInfo culture);




        public object Convert(object value)
        {
            return Convert((TSource)value, default(TParameter), System.Globalization.CultureInfo.CurrentCulture);
        }


        public object ConvertBack(object value)
        {
            return Convert((TTarget)value, default(TParameter), System.Globalization.CultureInfo.CurrentCulture);
        }


        public bool CanConvert(object value)
        {
            return value is TSource;
        }


        public bool CanConvertBack(object value)
        {
            return value is TTarget;
        }


    }


}
